package com.sg.service.base.app.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sg.common.util.CommonFunctionHelper;
import com.sg.dto.base.app.req.BatchQueryHypertextContentReq;
import com.sg.dto.base.app.req.QueryBusAppHypertextContentDetailReq;
import com.sg.dto.base.app.req.QueryBusAppHypertextContentListReq;
import com.sg.entity.OmsBizAppHypertextContent;
import com.sg.service.base.app.MOmsBizAppHypertextContentService;
import com.wicket.okrapp.common.dto.FieldInfo;
import com.wicket.okrapp.common.exception.BizException;
import com.wicket.okrapp.dal.mapper.mbg.OmsBizAppHypertextContentMapper;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author ：
 * @version 1.0
 * @since 2022/1/19 15:39
 */
@Service
public class MOmsBizAppHypertextContentServiceImpl
        extends ServiceImpl<OmsBizAppHypertextContentMapper, OmsBizAppHypertextContent>
        implements MOmsBizAppHypertextContentService {

    @Autowired
    OmsBizAppHypertextContentMapper omsBizAppHypertextContentMapper;

    /**
     * 3-5-2新增超文本内容[3136]
     * gen by moon at 11/9/2023, 10:15:10 PM
     */
    @Trace(operationName = "3-5-2新增超文本内容")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String addHypertextContent(OmsBizAppHypertextContent omsBizAppHypertextContent) {
        omsBizAppHypertextContent.setHypertextContentId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
        omsBizAppHypertextContent.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
        omsBizAppHypertextContent.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
        omsBizAppHypertextContent.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        omsBizAppHypertextContent.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        omsBizAppHypertextContent.setIsValid("FALSE");
        omsBizAppHypertextContent.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
        omsBizAppHypertextContent.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
        if (super.save(omsBizAppHypertextContent)) {
            return omsBizAppHypertextContent.getHypertextContentId();
        } else {
            return "-1";
        }

    }

    /**
     * 3-5-02查询业务应用超文本内容详情[3140]
     * gen by moon at 3/30/2023, 12:39:22 PM
     */
    @Trace(operationName = "3-5-02查询业务应用超文本内容详情")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public OmsBizAppHypertextContent queryBusAppHypertextContentDetail(QueryBusAppHypertextContentDetailReq reqDto) {

        try {
            reqDto.setIsValid("FALSE");
            reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
            reqDto.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
            QueryWrapper<OmsBizAppHypertextContent> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<OmsBizAppHypertextContent> retList = super.list(queryWrapper);
            if (retList != null && retList.size() > 0) {
                OmsBizAppHypertextContent retData = retList.get(0);

                return retData;
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * 3-3-05修改超文本内容[3626]
     * gen by moon at 10/15/2022, 5:45:09 PM
     */
    @Trace(operationName = "3-3-05修改超文本内容")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateHypertextContent(OmsBizAppHypertextContent omsBizAppHypertextContent) {

        return super.updateById(omsBizAppHypertextContent);
    }

    /**
     * 3-5-2批量查询超文本内容[4226]
     * gen by moon at 10/20/2023, 9:32:06 AM
     */
    @Trace(operationName = "3-5-2批量查询超文本内容")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OmsBizAppHypertextContent> batchQueryHypertextContent(BatchQueryHypertextContentReq reqDto) {

        try {
            QueryWrapper<OmsBizAppHypertextContent> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
            if (reqDto.getHypertextContentList() == null || reqDto.getHypertextContentList().isEmpty()) {
                return new ArrayList<>();
            }
            queryWrapper.in("releation_cont_id", reqDto.getHypertextContentList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsBizAppHypertextContent.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsBizAppHypertextContent.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsBizAppHypertextContent.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsBizAppHypertextContent>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * 3-5-2批量删超文本内容[4227]
     * gen by moon at 10/15/2022, 5:45:10 PM
     */
    @Trace(operationName = "3-5-2批量删超文本内容")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchDeleteHypertextContent(List<String> reqDto) {

        if (reqDto == null || reqDto.size() == 0) {
            return false;
        }

        return super.removeByIds(reqDto);
    }

    /**
     * M3-5-2构造业务应用超文本测试验证数据[4474]
     * gen by moon at 10/15/2022, 5:45:11 PM
     */
    @Trace(operationName = "M3-5-2构造业务应用超文本测试验证数据")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String buildBizAppHypertextContentTest(OmsBizAppHypertextContent omsBizAppHypertextContent) {
        omsBizAppHypertextContent.setHypertextContentId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
        omsBizAppHypertextContent.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
        omsBizAppHypertextContent.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
        omsBizAppHypertextContent.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        omsBizAppHypertextContent.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        omsBizAppHypertextContent.setIsValid("FALSE");
        omsBizAppHypertextContent.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
        omsBizAppHypertextContent.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
        if (super.save(omsBizAppHypertextContent)) {
            return omsBizAppHypertextContent.getHypertextContentId();
        } else {
            return "-1";
        }

    }

    /**
     * 3-5-2查询业务应用超文本内容列表[4616]
     * gen by moon at 10/15/2022, 5:45:12 PM
     */
    @Trace(operationName = "3-5-2查询业务应用超文本内容列表")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OmsBizAppHypertextContent> queryBusAppHypertextContentList(QueryBusAppHypertextContentListReq reqDto) {

        try {
            QueryWrapper<OmsBizAppHypertextContent> queryWrapper = new QueryWrapper<>();


            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsBizAppHypertextContent.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsBizAppHypertextContent.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsBizAppHypertextContent.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsBizAppHypertextContent>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

}

